window.EVN = {
    dev: true,
    test: false,
}


//生产环境地址
var _baseUrl = "http://www.sgyhl18.club/";

if (EVN.dev) {
    var VConsole = new VConsole();
    //测试环境
    // _baseUrl = "http://test1.sgyhl18.club:88/"
    //_baseUrl = "http://192.168.0.105:88/"
}
$api.setStorage("URL", _baseUrl);

function request(_url, _data, _atype, callback, errback) {
    var _token = $api.getStorage("token") || "";
    console.log(JSON.stringify(_data));
    console.log($api.getStorage("URL") + _url);
    console.log(_atype);
    api.ajax({
        type: _atype ? 'get' : _atype,
        url: _baseUrl + _url,
        dataType: 'json',
        data: {
            values: _data
        },
        success: function(ret, err) {
            if (ret.code == 0) {
                typeof callback == "function" && callback(ret)
            } else {
                var _msg = (ret && ret.msg) || "接口请求失败,请稍后重试"
                $api.toast({
                    msg: _msg
                });
            }
        },
        timeout: 15000,
        error: function(ret, err) {
            var _msg = (ret && ret.msg) || "接口请求失败,请稍后重试"
            $api.toast({
                msg: _msg
            });
            typeof(errback) == "function" ? errback: default_err_fun
        }
    });
}

//下拉刷新
function init_refresh_down_jq() {
    api.setRefreshHeaderInfo({
        visible: true,
        bgColor: 'rgba(0,0,0,0)',
        textColor: '#666',
        textDown: '下拉刷新',
        textUp: '释放刷新'
    }, function(ret, err) {
        list_init();
        api.refreshHeaderLoadDone();
    });
}

function loadData(dataParam, _action_name, toast) {
    if (dataParam.offset == 0) {
        $("#listview").html('')
    }
    var url = _action_name;
    toast.loading({
        title: "加载中..."
    });
    jqajax(url, dataParam, "post", function(json) {
        console.log(JSON.stringify(json));
        if (json.datas == null) {
            api.toast({
                msg: "没有更多数据了！"
            });
            toast.hide();
            return;
        }
        //前台添加已失效状态start
        if ("app/task/createTaskList" == url) {
            for (var i = 0; i < json.datas.length; i++) {
                var temp = json.datas[i].stoptime;
                temp = Date.parse(new Date(temp.replace(/-/g, '/'))) / 1000;
                //alert("temp"+temp);
                //alert(new Date().getTime()/ 1000);
                if ((temp < new Date().getTime() / 1000) && (json.datas[i].taskState == 0)) {
                    json.datas[i].taskState = 4;
                }
            }
        }
        //前台添加已失效状态end
        //手续费处理start
        if ("app/user/balanceInfo" == url) {
            for (var i = 0; i < json.datas.length; i++) {
                var itemremarks = json.datas[i].remarks;
                var itemupdatebalance = json.datas[i].updatebalance;
                json.datas[i].updatebalance = ((itemremarks).indexOf('手续费') != -1) ? (parseFloat(itemremarks.substring((itemremarks).indexOf('手续费') + 3, itemremarks.length - 1)) + parseFloat(itemupdatebalance)) : itemupdatebalance;

            }
        }
        //手续费处理end
        //alert(JSON.stringify(json.datas));
        $("#listview").append(template("template_info", json.datas));
        toast.hide();
    });
}

//默认ajax错误
function default_err_fun() {
    //if(typeof(toast)!='undefined'){}
    toast.hide();
    toast.fail({
        title: "连接失败,网络故障!",
        duration: 2000
    });

}

/**
 *头顶栏样式
 */
function init_StatusBarStyle() {
    api.setStatusBarStyle({
        style: 'dark',
        color: '#e71515'
    });
}

//询问菜单切换
function footerSwitchBtn(obj, name, indexstr) {
    switch (indexstr) {
        case 'index':
            api.openWin({
                name: 'home_win',
                url: '../page_main/home_win.html?ver=' + Math.random(),
                pageParam: {}
            });
            break;
        case 'msg':
            api.openWin({
                name: 'msg_window',
                url: '../page_msg/msg_window.html?ver=' + Math.random(),
                pageParam: {}
            });
            break;
        case 'cun':
            api.openWin({
                name: 'quALL_win',
                url: '../page_cun/quALL_win.html?ver=' + Math.random(),
                pageParam: {}
            });
            break;
        case 'my':
            api.openWin({
                name: 'usercenter_window',
                url: '../page_system/usercenter_window.html?ver=' + Math.random(),
                pageParam: {}
            });
            break;
        default:

            break;
    }
}

$api.addEvt($api.dom('.aui-pull-left'), 'click', function() {
    api.closeWin();
});

/**
 *增加最后提示
 * @param {Object} div
 */
function addLastLi(div) {
    $(div).append('<li class="listView-item flex_center lastview">已到最后</li>');
}

//if(json.total==0||_page==maxpage){addLastULi("#listview");}
function addLastULi(div) {
    $(div).append('<ul class="listView lastview"><li class="listView-item flex_center">已到最后</li></ul>');
}

//
//<li class="listView-item">
//<div class="flex-left">年度：</div>
//<div class="flex-right">
//<select class="aui-input aui-text-left" id="year" name="year"></select>
//</div>
//</li>

//年份
function select_year_init(yearid) {
    var thisYear = new Date().getUTCFullYear();
    //今年
    var endYear = thisYear + 5;
    //结束年份
    var nat = document.getElementById(yearid);
    for (startYear = thisYear; startYear <= endYear; startYear++) {
        var option = document.createElement('option');
        option.value = startYear;
        var txt = document.createTextNode(startYear);
        option.appendChild(txt);
        nat.appendChild(option);
    }
}

/*
<script src="../../../../../css/Mobiscroll/dev/js/mobiscroll.core-2.6.2.js" type="text/javascript"></script>
<script src="../../../../../css/Mobiscroll/dev/js/mobiscroll.core-2.6.2-zh.js" type="text/javascript"></script>
<script src="../../../../../css/Mobiscroll/dev/js/mobiscroll.datetime-2.6.2.js" type="text/javascript"></script>
<link href="../../../../../css/Mobiscroll/dev/css/mobiscroll.core-2.6.2.css" rel="stylesheet" type="text/css" />
<link href="../../../../../css/Mobiscroll/dev/css/mobiscroll.animation-2.6.2.css" rel="stylesheet" type="text/css" />
<link href="../../../../../css/Mobiscroll/dev/css/mobiscroll.sense-ui-2.6.2.css" rel="stylesheet" type="text/css" />

* */
//init_date("#ls_date","date");
//初始化日期
function init_date(elid, _type) {
    //'date'
    var curr = new Date().getFullYear();
    var opt = {};
    opt.date = {
        preset: 'date'
    };
    opt.datetime = {
        preset: 'datetime',
        minDate: new Date(2012, 3, 10, 9, 22),
        stepMinute: 5
    };
    // maxDate:new Date(2019,7,30,15,44),
    opt.time = {
        preset: 'time'
    };
    opt.tree_list = {
        preset: 'list',
        labels: ['Region', 'Country', 'City']
    };
    opt.image_text = {
        preset: 'list',
        labels: ['Cars']
    };
    opt.select = {
        preset: 'select'
    };

    //date datetime time tree_list image_text select
    $(elid).val('').scroller('destroy').scroller($.extend(opt[_type], {
        theme: 'sense-ui',
        mode: 'scroller', //scroller
        display: 'bottom',
        lang: 'zh',
        dateFormat: 'yy-mm-dd'
    }));

}

function FormatDate(strTime) {
    var date = new Date(strTime);
    return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
}